import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class humo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class humo extends Actor
{
    public GreenfootImage img[];
    public int cont,direccion;
    public GreenfootSound ou;
    Mosquito mosquito;
    World mundo = getWorld();
    MundoMosco mundomosco;
    public void act() 
    {
        cambiaImagen();
        bajaVidaMosco();
        if(mundomosco.nivel==3)
        mueve();
    }    
    public humo(MundoMosco mund)
    {
        mundomosco=mund;
        img = new GreenfootImage [16];
        ou = new GreenfootSound("doh.wav");
        ou.setVolume(30);
        int i = 0;
        direccion=0;
        cont=0;
        for(int a = 0;a < 16; a++)
        {       
            img[a] = new GreenfootImage("h" + i + ".png");
            i++;
        }
    }
    public void cambiaImagen()
    {
        setImage(img[cont]);        
        if(cont == 15)
            cont = 0;
        else
            cont++;
     
    } 
    
    public void bajaVidaMosco()
    {
        Actor mosco;
         
          mosco=getOneIntersectingObject(Mosquito.class);
          if(mosco!=null){
          ou.play();
            mosquito.vidas--;}
    }
    
    public void obtenMosco(Mosquito mos)
    {
        mosquito=mos;
    }
    void mueve()
    {
        
        if(direccion==0)
        {
            if(getX()>55)
            {        
              setLocation(getX()-15, getY());
              if(getX()<=55)
              {
              
              direccion=1;
              }
            }
        }
       else 
       if(direccion==1)
        {
             
             setLocation(getX()+15, getY());
            if(getX()>=560)
            {
            
            direccion=0;
            }
        }
    }
}
